Skip to content

[rb] Move information examples #1826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 26, 2024

Conversation

aguspe
Copy link
Contributor

@aguspe aguspe commented Jul 24, 2024

User description

Description

This PR focuses on moving all the ruby information examples into the relevant spec file: https://www.selenium.dev/documentation/webdriver/elements/information/

Motivation and Context

It's important to make our examples easier to maintain and to have them all as running tests

Types of changes

  • Change to the site (I have double-checked the Netlify deployment, and my changes look good)
  • Code example added (and I also added the example to all translated languages)
  • Improved translation
  • Added new translation (and I also added a notice to each document missing translation)

Checklist

  • I have read the contributing document.
  • I have used hugo to render the site/docs locally and I am sure it works.

PR Type

Enhancement, Documentation


Description

  • Added new RSpec tests for element information in information_spec.rb.
  • Updated documentation to replace inline Ruby code examples with links to the corresponding RSpec tests.
  • Changes applied to English, Japanese, Brazilian Portuguese, and Simplified Chinese documentation.

Changes walkthrough 📝

Relevant files
Tests
information_spec.rb
Add RSpec tests for element information                                   

examples/ruby/spec/elements/information_spec.rb

  • Added new RSpec tests for element information.
  • Tests include checks for display, enable, select status, tag name,
    size, CSS value, text, and attribute value.
  • +44/-0   
    Documentation
    information.en.md
    Update Ruby code examples to link to RSpec tests                 

    website_and_docs/content/documentation/webdriver/elements/information.en.md

  • Replaced inline Ruby code examples with links to the corresponding
    RSpec tests.
  • +22/-59 
    information.ja.md
    Update Ruby code examples to link to RSpec tests                 

    website_and_docs/content/documentation/webdriver/elements/information.ja.md

  • Replaced inline Ruby code examples with links to the corresponding
    RSpec tests.
  • +22/-59 
    information.pt-br.md
    Update Ruby code examples to link to RSpec tests                 

    website_and_docs/content/documentation/webdriver/elements/information.pt-br.md

  • Replaced inline Ruby code examples with links to the corresponding
    RSpec tests.
  • +22/-59 
    information.zh-cn.md
    Update Ruby code examples to link to RSpec tests                 

    website_and_docs/content/documentation/webdriver/elements/information.zh-cn.md

  • Replaced inline Ruby code examples with links to the corresponding
    RSpec tests.
  • +22/-59 

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Copy link

    netlify bot commented Jul 24, 2024

    👷 Deploy request for selenium-dev pending review.

    Visit the deploys page to approve it

    Name Link
    🔨 Latest commit c761095

    @qodo-merge-pro qodo-merge-pro bot added documentation Improvements or additions to documentation enhancement New feature or request Review effort [1-5]: 2 labels Jul 24, 2024
    Copy link
    Contributor

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ No key issues to review

    Copy link
    Contributor

    qodo-merge-pro bot commented Jul 24, 2024

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Maintainability
    Refactor repeated element lookups into a shared let statement

    Refactor repeated driver.find_element(name: 'email_input') calls into a let
    statement for DRY (Don't Repeat Yourself) principle adherence and improved test
    maintainability.

    examples/ruby/spec/elements/information_spec.rb [12-38]

    -displayed_value = driver.find_element(name: 'email_input').displayed?
    -enabled_value = driver.find_element(name: 'email_input').enabled?
    -selected_value = driver.find_element(name: 'email_input').selected?
    -tag_name = driver.find_element(name: 'email_input').tag_name
    -size = driver.find_element(name: 'email_input').size
    -css_value = driver.find_element(name: 'email_input').css_value('background-color')
    +let(:email_input) { driver.find_element(name: 'email_input') }
     
    +displayed_value = email_input.displayed?
    +enabled_value = email_input.enabled?
    +selected_value = email_input.selected?
    +tag_name = email_input.tag_name
    +size = email_input.size
    +css_value = email_input.css_value('background-color')
    +
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: Refactoring repeated element lookups into a let statement adheres to the DRY principle, making the tests more maintainable and reducing redundancy.

    9
    ✅ Use a range for size assertions to reduce test flakiness
    Suggestion Impact:The commit addressed the suggestion by changing the size assertions to check for positive values instead of exact dimensions, which aligns with the intention of reducing test flakiness.

    code diff:

    -    expect(size.width).to eq(147)
    -    expect(size.height).to eq(22)
    +    expect(size.width).to be_positive
    +    expect(size.height).to be_positive

    To avoid potential flakiness in tests that depend on specific dimensions, consider
    using a range or a less strict comparison unless the exact size is crucial for the
    functionality.

    examples/ruby/spec/elements/information_spec.rb [33-34]

    -expect(size.width).to eq(147)
    -expect(size.height).to eq(22)
    +expect(size.width).to be_within(5).of(147)
    +expect(size.height).to be_within(5).of(22)
     
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Using a range for size assertions can help reduce test flakiness caused by minor variations in element dimensions, improving test reliability and maintainability.

    7
    Enhance consistency in tab headers and descriptions across different language sections

    Ensure consistency in the documentation by using similar tab headers and
    descriptions across different language sections. The Ruby tab could be made
    consistent with others like JavaScript in terms of description and presentation.

    website_and_docs/content/documentation/webdriver/elements/information.ja.md [46-47]

    -{{< tab header="Ruby" text=true >}}
    +{{< tab header="Ruby" text=true description="Ruby example for element visibility" >}}
     {{< gh-codeblock path="/examples/ruby/spec/elements/information_spec.rb#L12">}}
     
    • Apply this suggestion
    Suggestion importance[1-10]: 6

    Why: Ensuring consistency in tab headers and descriptions enhances the maintainability and readability of the documentation, but it is a minor improvement.

    6
    Best practice
    Use more specific boolean matchers in RSpec tests

    Consider using a more specific matcher for the boolean expectations to improve test
    clarity and error messages. For instance, use be true instead of be_truthy for
    boolean checks to ensure that the value is exactly true, not just truthy.

    examples/ruby/spec/elements/information_spec.rb [13-23]

    -expect(displayed_value).to be_truthy
    -expect(enabled_value).to be_truthy
    -expect(selected_value).to be_falsey
    +expect(displayed_value).to be true
    +expect(enabled_value).to be true
    +expect(selected_value).to be false
     
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Using more specific matchers like be true and be false improves test clarity and ensures that the values are exactly true or false, not just truthy or falsy. This is a best practice for writing precise tests.

    8
    Consider removing unnecessary attributes in tab headers to clean up the layout

    To avoid confusion and maintain a clean layout, consider removing the text=true
    attribute if it is not necessary for functionality or consistency across
    documentation tabs.

    website_and_docs/content/documentation/webdriver/elements/information.ja.md [46-47]

    -{{< tab header="Ruby" text=true >}}
    +{{< tab header="Ruby" >}}
     {{< gh-codeblock path="/examples/ruby/spec/elements/information_spec.rb#L12">}}
     
    • Apply this suggestion
    Suggestion importance[1-10]: 5

    Why: Removing unnecessary attributes can clean up the layout, but this change is minor and does not significantly impact functionality or readability.

    5
    Accessibility
    Add tooltips or descriptive text to code blocks for better accessibility and usability

    To enhance the accessibility and usability of the documentation, consider adding
    tooltips or additional descriptive text to explain what the code block will
    demonstrate, especially for users who might be less familiar with Ruby or the
    specific methods used.

    website_and_docs/content/documentation/webdriver/elements/information.ja.md [46-47]

    -{{< tab header="Ruby" text=true >}}
    +{{< tab header="Ruby" text=true title="Check if email input is visible" >}}
    +# This Ruby example checks the visibility of the email input field.
     {{< gh-codeblock path="/examples/ruby/spec/elements/information_spec.rb#L12">}}
     
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Adding tooltips or descriptive text enhances the accessibility and usability of the documentation, making it more user-friendly, especially for those less familiar with Ruby or the specific methods used.

    8
    Enhancement
    Add descriptive comments within the Ruby code tabs for better clarity

    It's recommended to add a brief description or comment within the Ruby tab to
    explain what the linked Ruby code example demonstrates. This will improve the
    documentation's clarity and usefulness to the reader.

    website_and_docs/content/documentation/webdriver/elements/information.ja.md [46-47]

     {{< tab header="Ruby" text=true >}}
    +# Example demonstrating how to check visibility of an element
     {{< gh-codeblock path="/examples/ruby/spec/elements/information_spec.rb#L12">}}
     
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Adding a brief description within the Ruby tab improves the documentation's clarity and usefulness, especially for readers who may not be familiar with the code.

    7

    Copy link
    Member

    @harsha509 harsha509 left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Thank you @aguspe !

    @aguspe
    Copy link
    Contributor Author

    aguspe commented Jul 26, 2024

    @harsha509 I can see that the selenium manager examples are failing on mac and windows stable but I cannot reproduce that failure locally, I will investigate more the upcoming days but is not related to this PR

    @harsha509
    Copy link
    Member

    @harsha509 I can see that the selenium manager examples are failing on mac and windows stable but I cannot reproduce that failure locally, I will investigate more the upcoming days but is not related to this PR

    HI @aguspe,
    I re-ran the failed tests and its green now!

    @harsha509 harsha509 merged commit 3d5a027 into SeleniumHQ:trunk Jul 26, 2024
    9 checks passed
    selenium-ci added a commit that referenced this pull request Jul 26, 2024
    * Move information examples
    
    * Tests updated
    
    ---------
    
    Co-authored-by: Sri Harsha <12621691+harsha509@users.noreply.github.com> 3d5a027
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    documentation Improvements or additions to documentation enhancement New feature or request Review effort [1-5]: 2
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants